﻿Imports System.Xml
Imports System.Xml.Xsl

Partial Class UserCuntrols_ViewComments
    Inherits System.Web.UI.UserControl

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not String.IsNullOrEmpty(Request("SubCategory")) Then
            GetSuggestion(Request("SubCategory"))
        End If

    End Sub
    Private Sub GetSuggestion(ByVal _SubCategory As String)
        Dim _Suggestion As New BusinessLogic.Suggestion()
        _Suggestion.SubCategory = _SubCategory
        gvViewComments.DataSource = _Suggestion.Load()
        gvViewComments.DataBind()
    End Sub

    Protected Function CreateCommentsLink(ByVal _Text As String, ByVal _Link As String) As String
        Dim _Anchar = "<a href=""{0}"" target=""_blank"" style=""color:#0000FF;"" title=""{0}"" >{1}</a>"
        If Not _Link.StartsWith("http") Then
            _Link = String.Format("http://{0}", _Link)
        End If
        Return String.Format(_Anchar, _Link, _Text)
    End Function

    Protected Function RestrictLinkSize(ByVal _Link As String) As String
        Dim _Anchar = "<div title=""{0}"" >{1}</div>"
        If _Link.Length > 30 Then
            Return String.Format(_Anchar, _Link, _Link.Substring(0, 28) & "...")
        Else
            Return String.Format(_Anchar, _Link, _Link)
        End If
    End Function

    Protected Function CreateAddCommentsLink(ByVal Website_Name As String) As String
        Dim _Anchar = "<img title=""Read and Rate"" alt=""Read and Rate"" onclick=""AddComments('{0}');"" src=""{1}"" style=""cursor:pointer;""/>"
        'TopTen.aspx?Edit={0}
        Return String.Format(_Anchar, Website_Name, ResolveUrl("~/images/Read.gif"))
    End Function

    Protected Function StarRating(ByVal Rate As Integer) As String
        Dim _StarText As String = "<img src=""{0}"" title=""{1}"" alt=""{1}"" style=""float: left;"">"
        Dim _ResultString = New StringBuilder
        Dim i As Integer = 0
        For i = 1 To Rate
            _ResultString.AppendFormat(_StarText, ResolveUrl("~/\App_Themes/myTheme/images/FilledStar.png"), i)
        Next
        For i = (Rate + 1) To 10
            _ResultString.AppendFormat(_StarText, ResolveUrl("~/\App_Themes/myTheme/images/EmptyStar.png"), i)
        Next
        Return _ResultString.ToString()
    End Function
End Class
